<?php

namespace app\common\model\applymanager;

use think\Model;


class Business extends Model
{

    

    

    // 表名
    protected $name = 'self_join_business';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'user_info',
        'business_time_text',
        'pay_type_text',
        'pay_way_text'
    ];
    

    
    public function getPayTypeList()
    {
        return ['0' => __('Pay_type 0'), '1' => __('Pay_type 1')];
    }

    public function getPayWayList()
    {
        return ['0' => __('Pay_way 0'), '1' => __('Pay_way 1')];
    }


    public function getBusinessTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['business_time']) ? $data['business_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getPayTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
        $list = $this->getPayTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayWayTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_way']) ? $data['pay_way'] : '');
        $list = $this->getPayWayList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setBusinessTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


    public function getUserInfoAttr($value, $data){
        $value = isset($data['user_id']) ? $data['user_id'] : 0;
        return $value ? \app\common\model\User::getBaseInfoNosense($value) : '';
    }
}
